#ifndef __PLAYER_MANAGER_H__
#define __PLAYER_MANAGER_H__

#pragma once

#include <Singleton.h>
#include <SolarHashTable.h>

using namespace util;

class Player;
class ObjectFactory;
struct MSG_BASE_FORWARD;

class PlayerManager : public Singleton<PlayerManager>
{
public:
	PlayerManager();
	~PlayerManager();

public:

	BOOL				AddPlayer( Player * pPlayer );
	VOID				RemovePlayer( Player * pPlayer );
	Player*				FindPlayer( const DWORD dwUserKey );
	Player*				FindPlayer( const char *pszUserName );
	Player*				FindPlayerForObjectKey( const DWORD dwObjectKey );
	VOID				RemoveAllPlayer();

	/*
	BOOL				SendPacketToPlayer(DWORD dwObjKey, MSG_BASE_FORWARD * pMsg, WORD wSize);
	VOID				SendPacketToAllPlayer( MSG_BASE_FORWARD * pMsg, WORD wSize);
	VOID				SendPacketToAllPlayerExceptMe( DWORD dwObjectKey, MSG_BASE_FORWARD * pMsg, WORD wSize );
	
	VOID				Update(DWORD dwElapsedTime);
	*/

	template <class ObjectOperator>
	VOID		Foreach( ObjectOperator & op )
	{
		Player * pPlayer = NULL;
		m_pPlayerList->SetFirst();
		while( (pPlayer = m_pPlayerList->GetNext()) != NULL )
		{
			op(pPlayer);
		}
	}
//	VOID								RemoveAllPlayersOf( DWORD dwServerSessionIndex, ObjectFactory * pFactory );

	DWORD								GetNumberOfPlayers();
private:
	util::SolarHashTable<Player *> *	m_pPlayerList;
	util::SolarHashTable<Player *> *	m_pPlayerListForObjectKey;
};

#endif // __PLAYER_MANAGER_H__
